#ifndef _HALMEM_H_
#define _HALMEM_H_

#include <halmem_t.h>
#include <halmach_t.h>
#include <list.h>

/* 内存管理初始化函数 */

void hal_mem_init (void);

void mmapdsc_init (mach_t * mach);

uint_t mmapdsc_core_init (addr_t phyaddrstart, addr_t phyaddrend, mmapdsc_t * mmapdsc, uint_t curmindx);

void mmapdsc_t_init (mmapdsc_t * mmapdsc, addr_t phyaddrstart, addr_t phyaddrend, u32_t status, u32_t flag);

void mmclasslst_t_init (mmclasslst_t * mmclass, size_t blksz);

void phymem_init (void);

void phymem_t_init (phymem_t * phymem);

void mmapdsc_addto_memlist (mmclasslst_t * mmclass, mmapdsc_t * mmapdsc, uint_t flag);

void memlist_init (mach_t * mach, phymem_t * phymem); 

void krnl_mmapdsc_addto_memlist (mach_t * mach, phymem_t * phymem);

void mmapdsc_print (mach_t * mach);

/* 内存管理内存分配函数 */

mmclasslst_t * hal_onblksz_findmmclasslist (mmclasslst_t ** retmmclasslst, size_t * retmmsz, size_t blksz);

addr_t hal_onmmclasslst_allocblks (mmclasslst_t * mmclasslst, mmclasslst_t * mvtommclasslst, size_t blksz);

mmapdsc_t * hal_onmmclasslst_find_alloc_mmapdsc (mmclasslst_t * mmclasslst);

addr_t hal_onmmapdsc_allocblks (u32_t flag, u32_t mask, u32_t sbit, mmclasslst_t * mmclasslst, mmclasslst_t * mvtommclasslst);

addr_t hal_memalloc_blocks (size_t blksz);

addr_t hal_memalloc_blocks_core (size_t blksz);


mmapdsc_t * hal_onmmclasslst_find_free_mmapdsc (addr_t addr, mmclasslst_t * mmclasslst);

bool_t hal_onmmclasslst_freeblks (addr_t addr, mmclasslst_t * mmclasslst, mmclasslst_t * mvtommclasslst, size_t blksz);

bool_t hal_onmmapdsc_freeblks (addr_t addr, u32_t flag, u32_t mask, mmclasslst_t * mmclasslst, mmclasslst_t * mvtommclasslst);

bool_t hal_memfree_blocks (addr_t addr, size_t blksz);

bool_t hal_memfree_blocks_core (addr_t addr, size_t blksz);

#endif